package com.weitu.majorHazard.technicalReport.service.impl;

import com.weitu.accessory.util.AccessoryUtil;
import com.weitu.majorHazard.technicalReport.entity.TechnicalReport;
import com.weitu.majorHazard.technicalReport.mapper.TechnicalReportMapper;
import com.weitu.majorHazard.technicalReport.service.TechnicalReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/4/24.
 */
@Service
public class TechnicalReportServiceImpl implements TechnicalReportService {

    private final TechnicalReportMapper technicalReportMapper;

    @Autowired
    public TechnicalReportServiceImpl(TechnicalReportMapper technicalReportMapper){
        this.technicalReportMapper=technicalReportMapper;
    }

    @Override
    public int queryCount(Map<String, Object> map) {
        return this.technicalReportMapper.queryCount(map);
    }

    @Override
    public List<TechnicalReport> queryList(Map<String, Object> map) {
        return this.technicalReportMapper.queryList(map);
    }

    @Override
    @Transactional
    public boolean insertTechnicalReport(TechnicalReport technicalReport) {
        boolean flag= AccessoryUtil.saveAccerssoryInfo(technicalReport.getId());
        boolean flag2=false;
       int count= this.technicalReportMapper.insertTechnicalReport(technicalReport);
       if(count==1)
           flag2=true;
        return flag&&flag2;
    }

    @Override
    public TechnicalReport queryTechnicalReportById(String id) {
        return this.technicalReportMapper.queryTechnicalReportById(id);
    }

    @Override
    public boolean updateTechnicalReport(TechnicalReport technicalReport) {
        boolean flag2=false;
        int count=this.technicalReportMapper.updateTechnicalReport(technicalReport);
        if(count==1)
            flag2=true;
        boolean flag= AccessoryUtil.saveAccerssoryInfo(technicalReport.getId());
        return flag&&flag2;
    }

    @Override
    public int deleteTechnicalReport(String id) {
        return this.technicalReportMapper.deleteTechnicalReport(id);
    }

    @Override
    public int updateTechnicalReportBySubmit(TechnicalReport technicalReport) {
        return this.technicalReportMapper.updateTechnicalReport(technicalReport);
    }
}
